def binarySearch(arr,l,r,target):
    while  r>=l:
        mid=int(l+(r-l)/2)
        if arr[mid]==target:
            return mid
        if arr[mid]>target:
            r=mid-1
        else:l=mid-1
    
    return -1

arr = [2, 3, 4, 10, 40]
target = 10
l=0
r=len(arr)-1
print(binarySearch(arr,l,r,target))
